<template>
	<view>
		<!-- 顶部导航栏 -->
		<view class="hander-tab">
			<view class="hander-text">
				我关注的博主
			</view>
		</view>
		<!-- 博主头像 -->
		<scroll-view scroll-x="true"
			style="white-space: nowrap;position: sticky;top: 100rpx;background-color: #ffffff;z-index: 99;">
			<view v-for="(item,index) in followdata" style="display: inline-block;margin:30rpx 20rpx;">
				<view @click="changeuser(item,index)" class=""
					:style="index==userindex?'border: solid 6rpx #3668fc;':'border: solid 6rpx #fcfcfc;'"
					style="display: flex;align-items: center;flex-direction: column;border-radius: 50rpx;box-sizing: border-box;transition: all .5s;">
					<u--image radius="50" :showLoading="true" :src="item.user_pic" width="45px"
						height="45px"></u--image>
					<!-- <text style="font-size: 25rpx;">{{item.nickname}}</text> -->
				</view>
			</view>
			<u-notice-bar :text="notice" color="#ffffff" bgColor="#3668fc"></u-notice-bar>
		</scroll-view>
		<u-gap height="5" bgColor="#f0f3f5"></u-gap>
		<!-- 文章 -->
		<xz-article :postdata="articlesdata"></xz-article>
		<u-loadmore @loadmore="getfollowarticles(1)" :status="loading" loadingIcon="circle" loadmoreText="上拉发现更多角落"
			nomoreText="这个世界依旧空旷" loadingText="正在寻找世界上最后一个角落"></u-loadmore>
	</view>
</template>

<script>
	import xZarticle from "../../components/xz-article/xz-article.vue"
	export default {
		components: {
			xZarticle
		},
		data() {
			return {
				notice: '请勿发布违法违规内容，否则四点君会封号的哟！bug反馈反馈邮箱3082086388@qq.com',
				loading: 'loadmore',
				userindex: 0,
				followdata: [],
				articlesdata: [],
				//每页查询数据条数
				pagetotal: 10,
				//当前页
				pagesize: 1,
				user_id:null
			}
		},
		onLoad() {
			this.getmyfollow()
		},
		onReachBottom() {
			this.getfollowarticles(1)
		},
		methods: {
			getuser(){
				uni.getStorage({
					key:'userinfo',
					success: (res) => {
						this.user_id=res.data.id
					},
				})
			},
			showrzmessage(e) {

			},
			changeuser(i, e) {
				this.userindex = e
				this.getfollowarticle(i.id)
			},
			//根据选择的关注的用户查询他的文章
			getfollowarticle(id) {
				console.log(id);
				this.pagesize=1
				uni.request({
					url: 'http://127.0.0.1:3007/api/getfollowarticle',
					data: {
						follow_user_id: id,
						fans_user_id: this.user_id,
						pagetotal: this.pagetotal,
						pagesize: this.pagesize
					},
					success: (res) => {
						console.log(res);
						this.pagesize++
						this.articlesdata = res.data.results
					}
				})
			},
			getfollowarticles(id) {
				this.loading = 'loading'
				uni.request({
					url: 'http://127.0.0.1:3007/api/getfollowarticle',
					data: {
						follow_user_id: id,
						fans_user_id: this.user_id,
						pagetotal: this.pagetotal,
						pagesize: this.pagesize
					},
					success: (res) => {
						if (res.data.status == 0) {
							this.pagesize++
							this.articlesdata.push(...res.data.results)
							setTimeout(res => {
								this.loading = 'loadmore'
							}, 500)
						} else {
							setTimeout(res => {
								this.loading = 'nomore'
							}, 500)
						}
					}
				})
			},
			getmyfollow() {
				uni.request({
					url: 'http://127.0.0.1:3007/my/getmyfollow',
					data: {
						user_id: this.user_id,
						pagetotal: 10,
						pagesize: 1
					},
					success: (res) => {
						this.followdata = res.data.data
						this.getfollowarticle(this.followdata[0].id)
						console.log(res);
					}
				})
			},
			changeswiper(e) {
				this.swiperindex = e.current
			},
		}
	}
</script>

<style lang="scss">
	.hander-tab {
		position: sticky;
		z-index: 99;
		top: 0;
		display: flex;
		justify-content: space-between;
		/* #ifdef MP-WEIXIN */
		padding: 80rpx 20rpx 0rpx 20rpx;
		/* #endif */
		/* #ifndef MP-WEIXIN */
		padding: 0 20rpx;
		/* #endif */
		height: 100rpx;
		align-items: center;
		background-color: #ffffff;
	}

	.hander-text {
		font-size: 40rpx;
	}

	.hander-icon {
		display: flex;
		/* #ifdef MP-WEIXIN */
		margin-right: 180rpx;
		/* #endif */
	}

	.hander-icon .icon1 {
		margin-left: 30rpx;
	}
	
	.indicator {
		@include flex(row);
		justify-content: center;

		&__dot {
			height: 6px;
			width: 6px;
			border-radius: 100px;
			background-color: rgba(255, 255, 255, 0.35);
			margin: 0 5px;
			transition: background-color 0.3s;

			&--active {
				background-color: #ffffff;
			}
		}
	}
</style>